<?php
require_once("../admin_config.inc.php");

class test_setques
{
    private $table = null;
    
    function __construct()
    {
        // create a connection to the database
        $db = connect_db();
        
        $this->table = "test_setques";
    }
    
    function addSet($testid,$timetaken)
    {
        $setid = mt_rand();
        $test_id = mysql_real_escape_string($testid);
        $time = date('H:i:s');
        $time_taken = mysql_real_escape_string($timetaken);
        
        $data = array(  'setid' => $setid,
                        'test_id' => $test_id,
                        'time' => $time,
                        'time_taken' => $time_taken );
                        
        $keys = implode("`,`",array_keys($data));
        $values = implode("','",$data);
        
        $add_query = vsprintf("insert into {$this->table}(`%s`) values('%s')",array($keys,$values));
        $add_res = mysql_query($add_query);
        
        return $add_res;
    }
    
    function delSet($set_id)
    {
        $setid = mysql_real_escape_string($set_id);
        
        $del_query = "delete from $this->table where setid = $setid";
        $del_res = mysql_query($del_query);
        
        return $del_res;
    }
    function editTimeTaken($set_id,$testid,$newtime)
    {
        if(!is_int($newtime))
            return false;
            
        $time_taken = mysql_real_escape_string($newtime);
        $setid = mysql_real_escape_string($set_id);
        $test_id = mysql_real_escape_string($testid);
        
        $update_query = "update {$this->table} set time_taken = {$time_taken} where setid = {$setid} and test_id = {$test_id}";
        $update_res = mysql_query($update_query);
        
        return $update_res;
    }
}
$ob = new test_setques();
$ob->delSet(10);
?>
